//
//  SmsCodeInputView.m
//  BaseProject
//
//  Created by 王洋 on 2021/1/20.
//  Copyright © 2021 王洋. All rights reserved.
//

#import "SmsCodeInputView.h"

@implementation SmsCodeInputView

+ (CGFloat)calculateHeight {
    return 126;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    
    self.field = [[WGDigitField<WGDigitView<UIView *> *> alloc] initWithDigitViewInitBlock:^WGDigitView<UIView *> * (NSInteger index){
        UIView *background = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 45)];
        background.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5];
        background.layer.cornerRadius = 4.0f;
        
        return [[WGDigitView<UIView *> alloc] initWithBackgroundView:background digitFont:[UIFont systemFontOfSize:26.f weight:UIFontWeightMedium] digitColor:[UIColor whiteColor]];
        
    } numberOfDigits:6 leadSpacing:0 tailSpacing:0 weakenBlock:^(WGDigitView<UIView *> * _Nonnull digitView) {
        
        
    } highlightedBlock:^(WGDigitView<UIView *> * _Nonnull digitView) {
        
    } fillCompleteBlock:^(WGDigitField * _Nonnull digitField, NSArray<WGDigitView<UIView *> *> * _Nonnull digitViewArray, NSString * _Nonnull text) {
        
        [digitField resignFirstResponder];

        //输入结束回调
        if (self.SmsCodeInputViewBlock) {
            self.SmsCodeInputViewBlock(SmsCodeInputActionType_handleCode,text);
        }
        
    }];
    
    [self.codeBGView addSubview:self.field];
    [self.field mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    
    [self.field becomeFirstResponder];
}


- (IBAction)codeAction:(id)sender {
    if (self.SmsCodeInputViewBlock) {
        self.SmsCodeInputViewBlock(SmsCodeInputActionType_code,@"");
    }
}


@end
